<template>
  <div :class="{'theme-market': showMarketingBar}">
    <section class="c-maxh440 c-text-hidden c-p" @click="clickLiveCover" v-if="!playing">
      <img class="c-w100" :src="$addXossFilter(liveInfo.cover, require('../../../assets/defult270.png'))" alt="" />
      <div class="c-translucent-balck60 c-pa  c-p-l0 c-p-t0 c-p-r0 c-h c-flex-row c-aligni-center c-justify-center" v-show="liveInfo.videoIntroUrl">
        <span class="iconfont c-fc-white c-fs100">&#xe869;</span>
      </div>
    </section>
    <section v-show="liveInfo.videoIntroUrl && playing" class="c-w100 c-hh360 " id="liveVideoIntroParent">
    </section>
    <!-- 营销活动 -->
    <flash-sales-time-new
      v-if="showMarketingBar"
      :type="liveInfo.sales ? 'isSale' : liveInfo.bargain ? 'isBargain' : ''"
      :originalPrice="liveInfo.price"
      :price="liveInfo.bargain ? liveInfo.bargain.reservePrice : liveInfo.sales ? liveInfo.sales.price: ''"
      :startTime="liveInfo.bargain ? liveInfo.bargain.startTime : liveInfo.sales ? liveInfo.sales.sales.startTime : ''"
      :endTime="liveInfo.bargain ? liveInfo.bargain.endTime : liveInfo.sales ? liveInfo.sales.sales.endTime : ''"
      :isLimit="liveInfo.sales && liveInfo.sales.limit == 0 || (liveInfo.bargain && liveInfo.bargain.isLimitStock == 2) ? false : true"
      :stockBargain="liveInfo.bargain && liveInfo.bargain.stock"
      :bargainStatus="liveInfo.bargain && liveInfo.bargain.status"
      :isPreheat="liveInfo.bargain && liveInfo.bargain.isPreheat"
      :salesTag="liveInfo.sales && liveInfo.sales.sales.tahs"
      :stock="liveInfo.sales ? liveInfo.sales.balance: ''"
      :optimal="optimal"
      @falshSalesTime="falshSalesTime"
      @finishFlashSales="finishFlashSales"
    ></flash-sales-time-new>

    <section class="c-bd-b12-f5">

      <price-bar class="c-ph0 c-pt20" v-if="liveInfo.isBuyed != 1 && !(liveInfo.sales || liveInfo.bargain)"
        :dataInfo="liveInfo"
        :styleType="2"
        :isChain="isChainProd"
        :chainInfo="chainInfo">
      </price-bar>
      <!-- 积分及会员，大转盘，vip入口优惠提示 -->
      <!-- 付费 && 单卖 && 非IOS && (没有权限或者已有权限（处于试看状态) -->
      <discount-info class="c-mt8" v-if="liveInfo.payType == 2 && !isiOS && !liveInfo.hasPermission"
        :couponList="couponList"
        :dataInfo="liveInfo"
        :chainInfo="chainInfo"
        :isMarketing="isMarketing"
        @clickShowCoupon="showCoupon = true"
      >
      </discount-info>
      <vip-entry class="c-ph24 c-mt20"
        v-if="(!liveInfo.isFriendHelper || companyAuth.enableFriendHelper == 0) &&!liveInfo.hasPermission && !$isWxAppIos() && !isiOS"
        :dataInfo="liveInfo"
      ></vip-entry>
      <div class="c-ph24 c-mt24">
        <span class="c-fs30 c-fw-b c-fc-xblack c-lh48">{{liveInfo.name}}</span>
      </div>
      <div class="c-ph24 c-pb20 c-flex-row c-fs20 c-justify-sb c-pt20" :class="liveInfo.sales?'c-pb16 c-bd-b1':''">
        <span class="c-fc-sblack">共含{{liveInfo.detailNum}}课节<b class="c-fc-xblack c-ml16 c-fw-n" v-if="!liveInfo.isHideLimit">剩余{{liveInfo.limitNum-liveInfo.saleNum}}名额</b>
          <b class="theme-fc c-ml16 c-fw-n" v-if="liveInfo.isBuyed == 1">
            <span v-if="liveInfo.price * 1 > 0">{{'￥' | iosPriceFilter('PrivateClass')}}</span>
            <span class="">{{liveInfo.payType | priceValueFilter(liveInfo.price, 115)}}</span>
          </b>
        </span>
        <span class="c-fs20" :class="liveInfo.classStatus == 1 ? 'c-fc-xlred':liveInfo.classStatus == 2 ?'c-fc-xblack':liveInfo.classStatus == 3 ?'c-fc-gray':'' ">
          {{liveInfo.classStatus==1?liveInfo.classBeginAt?liveInfo.classBeginAt+'开课':'':statusMap[liveInfo.classStatus]}}
        </span>
      </div>
      <!-- 非强制表单入口||(liveInfo.hasFormLog&&liveInfo.enableEdit==2&& isShowFormlg&& liveInfo.isRelForm == true -->
      <formEntry v-if="liveInfo.hasPermission && ((liveInfo.collectPage==3&& liveInfo.isRelForm == true && liveInfo.hasFormLog == false && isShowFormlg)||(liveInfo.payType != 4&&(liveInfo.hasFormLog&&liveInfo.enableEdit==2&& isShowFormlg&& liveInfo.isRelForm == true)))"
        relType="18"  :relId="liveInfo.classId"  :dataInfo="liveInfo"
        classObject="c-fs22" fontSizeClass="c-fs20" iconSizeClass="c-fs14" topClass="c-bd-t12-f5 c-bd-b12-f5 "
        @goForm="goJoinInfo(0)" ></formEntry>
      <div class="c-mh24 c-flex-row c-fs20 c-justify-sb c-pv20 c-bd-t1" v-if="liveInfo.classBeginAt!=0">
        <span class="c-fc-gray">授课时间： <b class="c-fc-xblack c-fw-n">{{liveInfo.classBeginAt!=0?liveInfo.classBeginAt:''}}</b></span>
      </div>
      <div class="c-mh24 c-flex-row c-fs20 c-justify-sb c-pv20 c-bd-t1" v-if="liveInfo.applyEndAt!=0">
        <span class="c-fc-gray">报名截止：<b class="c-fc-xblack c-fw-n"> {{liveInfo.applyEndAt!=0?liveInfo.applyEndAt:''}}</b></span>
      </div>
      <bargain-rules
        v-if="liveInfo.bargain != null && !liveInfo.isBuyed"
        :isPreheat="liveInfo.bargain.isPreheat"
        :status="liveInfo.bargain.status"
        class="c-bd-t12-f5"
      ></bargain-rules>
    </section>
    <collocation-buy-com :prodInfo="{prodType: 115, prodId: liveInfo.classId}" :relateCollocationArr="relateCollocation"></collocation-buy-com>
    <h2 class="c-ph24 c-fw-n c-fc-xblack c-fs28 c-fw-b c-pt20 c-textAlign-c">详情介绍</h2>
    <div class="theme-bg-gradient c-center c-mt14 c-ww32 c-hh6 c-br3"></div>
    <div v-if="liveInfo.description" class="c-mt28 c-pb120 c-ph24">
      <div @click="clickDesc" class="tinymce-text c-ww-bw c-ww-ba c-contexty-scroll" :class="[cfg.isCopyPicture == 0 ? 'closeBig' : 'aCloseBig', cfg.isCopy == 0 ? 'copyNot' : '']" v-html="liveInfo.description"></div>
    </div>
    <loading-status-tem v-else :noData="!liveInfo.description" :noDataText="'暂无详情介绍'" noDataStyle="padding: 0px" :class="'c-bg-white c-hh640 c-flex-column c-flex-center'"></loading-status-tem>
    <bottom-buy-com :ckFrom="115"
      :isNeedPay="liveInfo.isBuyed == 0 && liveInfo.payType == 2 && liveInfo.isFreeBuy == 0 && liveInfo.price * 1 > 0"
      :showBuyButton="liveInfo.isBuyed == 0 && liveInfo.payType == 2 && liveInfo.isFreeBuy==0 && liveInfo.price * 1 > 0 && liveInfo.isFull == 0 && !classOver"
      @spreadInvite="spreadInvite"
      @invitePoster="invitePoster">
      <div class="c-w0 c-hh64 c-flex-grow1 c-fs28">
        <!-- -2拉黑  -1付费删除 isFreeBuy:是否是免费 isBuyed：是否有权限-->
        <template v-if="liveInfo.studentTipStatus==-2">
          <div class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="onBlacklistTipOpen">去上课</div>
        </template>
        <template v-else>
          <!-- 砍价购 -->
          <template v-if="liveInfo.bargain != null && ((liveInfo.bargain.status == 1 && liveInfo.bargain.isPreheat == 1) || liveInfo.bargain.status == 2) && liveInfo.isBuyed == 0 && liveInfo.payType == 2 && liveInfo.isFreeBuy == 0 && liveInfo.price * 1 > 0 && liveInfo.isFull == 0 && !classOver">
            <div class="c-flex-row c-w100 c-hh64 c-flex-center">
              <div
                class="c-flex-column c-justify-sa c-aligni-center theme-fc c-hh64 theme-bd1 c-w50 c-br32 c-mh10"
                @click="clickBuy"
              >
                <span class="c-fs20 c-lh">{{getBuyBtnTitle}}</span>
                <span class="c-fs22 c-lh c-mt4"><span class="c-fs20">{{'￥' | iosPriceFilter()}}</span>{{calculationPrice}}</span>
              </div>
              <!-- 未发起砍价 -->
              <template v-if="liveInfo.bargain.userType == 1">
                <div
                  class="c-flex-row c-flex-center c-fc-white c-hh64 c-w50 c-fs28 c-br32 theme-bg-gradient"
                  @click="handleClickBargainDetail(liveInfo.bargain.bargainId)"
                >正在砍价</div>
              </template>
              <template v-if="liveInfo.bargain.userType == -1">
                <div
                  class="c-flex-column c-justify-sa c-aligni-center c-fc-white c-hh64 c-w50 c-br32"
                  :class="(liveInfo.bargain.status == 1 && liveInfo.bargain.isPreheat == 1) ? 'c-bg-d7' : 'theme-bg-gradient'"
                  @click="handleClickBargainDetail(liveInfo.bargain.bargainId)"
                >
                  <span class="c-fs20 c-lh">砍价享</span>
                  <span class="c-fs22 c-lh c-mt4"><span class="c-fs20">{{'￥' | iosPriceFilter()}}</span>{{Number(liveInfo.bargain.reservePrice).toFixed(2)}}</span>
                </div>
              </template>
            </div>
          </template>
          <!-- 限时购 -->
          <div v-if="liveInfo.sales && faStatus == 2 && liveInfo.isBuyed == 0 && liveInfo.payType == 2 && liveInfo.isFreeBuy == 0 && liveInfo.price * 1 > 0 && liveInfo.isFull == 0 && !classOver" class="c-fc-white c-lh c-flex-column c-flex-center c-h c-br36 theme-bg-gradient" @click="clickBuy()">
            <span class="c-fs20 c-lh">{{getBuyBtnTitle}}</span>
            <!-- <span class="c-fs22 c-lh c-mt4"><span class="c-fs20">{{'￥' | iosPriceFilter()}}</span>{{calculationPrice}}</span> -->
          </div>
          <!-- 付费 -->
          <div v-if="(liveInfo.sales == null || faStatus == 1) && liveInfo.bargain == null && liveInfo.isBuyed == 0 && liveInfo.payType == 2 && liveInfo.isFreeBuy==0 && liveInfo.price * 1 > 0 && liveInfo.isFull == 0 && !classOver"
            class="c-fc-white c-lh c-flex-column c-flex-center c-h c-br36 theme-bg-gradient" @click="clickBuy">
            <span class="c-fs20 c-lh">立即购买</span>
            <!-- <span class="c-fs22 c-lh c-mt4"><span class="c-fs20">{{'￥' | iosPriceFilter()}}</span>{{calculationPrice}}</span> -->
          </div>
          <!-- 免费 -->
          <div v-if="liveInfo.isBuyed == 0 &&liveInfo.payType==1 && liveInfo.isFreeBuy==0 && liveInfo.isFull == 0 && !classOver"
            class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="clickSignUp">立即报名</div>
          <div v-if="liveInfo.isBuyed == 1" class="c-fc-white c-lh c-flex-row c-flex-center c-hh64 c-br36 theme-bg" @click="goClassList">去上课</div>
          <!-- 免费加入 -->
          <div v-if="liveInfo.payType!=3 && liveInfo.isBuyed == 0 && liveInfo.isFreeBuy==1 && liveInfo.isFull == 0 && !classOver"
            class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg" @click="clickSignUp">立即报名</div>
          <!-- 加密 -->
          <div v-if="liveInfo.isBuyed == 0 &&liveInfo.payType == 3 && liveInfo.isFull == 0 && !classOver" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg"
            @click="clickEnterPwd">立即报名</div>
          <!-- 名单审核参与-->
          <div v-if="liveInfo.isBuyed == 0 && liveInfo.payType == 4 && liveInfo.isFull == 0 && !classOver" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 theme-bg"
            @click="openCheckTip()">立即报名</div>
          <div v-if="liveInfo.isBuyed == 0 && liveInfo.isFull == 1 && !classOver" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 c-bg-ccc">此班已满员</div>
          <div v-if="liveInfo.isBuyed == 0 && classOver" class="c-fc-white c-lh c-flex-row c-flex-center c-h c-br36 c-bg-ccc">报名已截止</div>
        </template>
      </div>
    </bottom-buy-com>
    <coupon-list-com
      @closeModal="closeModal"
      @getCouponList="getCouponList"
      :couponIsPage="couponIsPage"
      :couponLoading="couponLoading"
      :couponList="couponList"
      :showCoupon="showCoupon"
      :prodId="Number(lId)"
      :prodType="115"
      :isMarketing="isMarketing"
      :dataInfo="liveInfo"
      :chainInfo="chainInfo"
    >
    </coupon-list-com>
    <share-masker :isShowShare="isShowShare" v-if="isShowShare" @closeShare="isShowShare=false;"></share-masker>
    <comfirm-com :showPassword="showPassword" :noticeText="noticeText" :text="'输入密码进入直播'" :placeholderText="'请输入密码'" @changePsw="changePsw" @closePassword="showPassword = false"
      @submitPassword="submitPassword"></comfirm-com>
    <!-- 关注二维码 -->
    <offical-account
      v-if="liveInfo && liveInfo.bargain"
      :showAccountQcode="showAccountQcode"
      :desc="officalDesc"
      :imgSrc="$addXossFilter(mpQrcode)"
      @hideDialog="hideDialog"
    ></offical-account>
    <promote-income
      v-if="liveInfo && liveInfo.classId"
      :showInvitionCard="liveInfo.isInvitionCard == 1 && liveInfo.bargain == null && liveInfo.sales == null"
      :showMarketingCard="liveInfo.bargain || liveInfo.sales"
      :prodId="liveInfo.classId"
      :prodType="115"
      @goInvite="spreadInvite"
      @goMarketingPoster="invitePoster"
    >
    </promote-income>
    <!-- 入学证书 -->
    <enrol-cer :isReceivedStudy="isReceivedBuy" ref="enrolcerCom" :bigType="2"></enrol-cer>
  </div>
</template>
<script>
import { getXgplayer, destoryPlayer } from "@/utils/xgplayerJs.js";
import shareMasker from "@/components/templates/common/shareMasker.vue";
import ComfirmCom from "@/components/templates/common/comfirmCom.vue";
import {utilJs, wxUtilJs} from "@/utils/common.js";
import bottomBuyCom from "@/components/templates/common/bottomBuyCom.vue";
import PriceBar from '@/components/templates/common/priceBar.vue';
import FlashSalesTimeNew from "@/components/templates/flashSalesTimeNew.vue";
import bargainRules from '@/components/templates/bargain/bargainRules';
import officalAccount from '@/components/templates/common/officalAccount';
import couponListCom from "@/components/templates/couponListCom.vue";
import collocationBuyCom from '@/components/templates/collocationBuyCom';
import PromoteIncome from '@/components/templates/common/promoteIncome.vue';
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
import enrolCer from "@/components/templates/learnAndachCer/enrolCer.vue";
import formEntry from "@/components/homePage/form/formEntry.vue"
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import DiscountInfo from "@/components/templates/common/discountInfo.vue";
import VipEntry from "@/components/templates/common/vipEntry.vue";
let classId = "";
let qPlayer = null;
let isClicking = false;
// let inputScrollTop = 0;
export default {
  name: "ClassDetail",
  components: {
    DiscountInfo,
    VipEntry,
    shareMasker,
    ComfirmCom,
    bottomBuyCom,
    PriceBar,
    FlashSalesTimeNew,
    bargainRules,
    officalAccount,
    couponListCom,
    collocationBuyCom,
    PromoteIncome,
    enrolCer,
    formEntry,
    loadingStatusTem
  },
  beforeRouteUpdate(to, from, next) {
    if (to.path === from.path) {
      window.location.reload(true)
    }
  },
  data() {
    return {
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : "mb5_default",
      liveInfo: {}, //isBuyed是否有权限，payType类型，isFreeBuy是否免费加入
      classOver: false, //是否已截止
      statusMap: {
        2: "已开课",
        3: "已过期"
      },
      showPassword: false, //显示密码输入
      noticeText: "",
      playing: false,
      vipType: localStorage.getItem("vipType" + localStorage.getItem("userId")),
      isShowFormlg:localStorage.getItem("showForm") == 1 ? true : false,
      cfg: JSON.parse(localStorage.getItem("cfg")),
      isiOS: false,
      faStatus: 1,
      showAccountQcode: false,
      officalDesc: '关注我们后才可发起砍价哦',
      mpQrcode: '',
      couponList: [],
      couponIsPage: false,
      couponPage: 1,
      couponLoading: false,
      showCoupon:false,
      bindPhoneSetting: null,
      relateCollocation: [],
      isReceivedBuy:0,
      chainInfo: '',
      isChainProd: false,
      optimal:null,
      isOpenIosGzhPay:true
    };
  },
  created() {
    utilJs.appShare(this);
    console.log(this.liveInfo.intro)
    let reIdArr = window.location.href.split("classId=");
    if (reIdArr.length > 1 && reIdArr[1]) {
      let rId = reIdArr[1].split("&").length > 0 ? reIdArr[1].split("&")[0] : reIdArr[1];
      window.localStorage.setItem("classId", rId);
    }
  },
  mounted() {},
  computed: {
    showMarketingBar() {
      return this.liveInfo && (this.liveInfo.sales || (this.liveInfo.bargain && ((this.liveInfo.bargain.status == 1 && this.liveInfo.bargain.isPreheat == 1) || this.liveInfo.bargain.status == 2)))
    },
    //单卖&&没有权限&&价格大于0&&（加入形式&&不是好友助力）&&（优惠券||vip svip折扣信息||积分抵扣）&&（是否参与营销）
    showDiscount() {
      let showdiscount = !this.liveInfo.isBuyed && Number(this.liveInfo.price) > 0 && !this.liveInfo.isFriendHelper
      return showdiscount
    },
    isMarketing() {
      let isMarketing = this.liveInfo &&
        ((this.liveInfo.bargain
          && ((this.liveInfo.bargain.status == 1 &&
            this.liveInfo.bargain.isPreheat == 1) || this.liveInfo.bargain.status == 2)) || this.liveInfo.isFriendHelper)
      return isMarketing
    },
     // 获取按钮专享价名称
    getBuyBtnTitle() {
      // 会根据是否开启ios支付区别文案展示
      let defaultTxt = '立即' + (this.isOpenIosGzhPay ? '购买' : '体验');
      if (this.optimal) {
        const agentName = utilJs.getCustNameMap();
        let btnTxt = '立即购买'
        let chainPrice = this.chainInfo && this.chainInfo.isChainProd ? (this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? this.chainInfo.reorderBonus : this.chainInfo.enableOrderDiscount == 1 ? this.chainInfo.orderBonus : this.liveInfo.price) : this.liveInfo.price;
        let idDiscount = (this.vipType == 3 || this.vipType > 4) && this.liveInfo.commonProdInfo && this.liveInfo.commonProdInfo.agentDiscount < 100
          ? this.liveInfo.commonProdInfo.agentDiscount
          : (this.vipType == 4 && this.liveInfo.svipDiscount < 100)
            ? this.liveInfo.svipDiscount
            : (this.vipType == 2 && this.liveInfo.vipDiscount < 100)
              ? this.liveInfo.vipDiscount
              : 100
        let discountPrice = Number(this.liveInfo.price * idDiscount / 100).toFixed(2);
        if (this.chainInfo && this.chainInfo.isChainProd && Number(chainPrice) <= Number(discountPrice)) {
          let chainName = this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? '复购' : (this.chainInfo.userType == 1 ? '普通用户' : this.chainInfo.userType2Name[this.chainInfo.userType])
          btnTxt = chainPrice != this.liveInfo.price && chainName ? chainName + '专享价' : defaultTxt;
        } else {
          btnTxt = discountPrice * 1 != this.liveInfo.price ? (this.vipType != 1 ? (this.vipType == 2 ? 'VIP专享价' : this.vipType == 4 ? 'SVIP专享价' : agentName[this.vipType] + '专享价') : defaultTxt) : defaultTxt;
        }
        if (this.liveInfo.sales && this.optimal.optimalPriceType == 101) {
          btnTxt = defaultTxt;
        }
        return btnTxt
      }
      return defaultTxt
    },
    //营销原价计算价格
    calculationPrice() {
      let idDiscount = (this.vipType == 3 || this.vipType > 4) && this.liveInfo.commonProdInfo && this.liveInfo.commonProdInfo.agentDiscount < 100
          ? this.liveInfo.commonProdInfo.agentDiscount
          : (this.vipType == 4 && this.liveInfo.svipDiscount < 100)
            ? this.liveInfo.svipDiscount
            : (this.vipType == 2 && this.liveInfo.vipDiscount < 100)
              ? this.liveInfo.vipDiscount
              : 100
      let calculationPrice = Number(this.liveInfo.price * idDiscount / 100).toFixed(2);
      if (this.optimal) {
        // 链动价格
        let chainPrice = this.chainInfo && this.chainInfo.isChainProd ? (this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? this.chainInfo.reorderBonus : this.chainInfo.enableOrderDiscount == 1 ? this.chainInfo.orderBonus : this.liveInfo.price) : this.liveInfo.price;
        // 当链动价格存在且链动价格跟常规身份价格对比时，如果链动小于或者等于身份价格取链动价格
        calculationPrice = this.chainInfo && this.chainInfo.isChainProd && Number(chainPrice) <= Number(calculationPrice) ? chainPrice : calculationPrice;
        if (this.liveInfo.isFriendHelper) {
          calculationPrice = Number(this.optimal.optimalPrice).toFixed(2);
        }
      }
      return calculationPrice;
    },
  },
  watch: {},
  methods: {
    judgeCompliance() {
      let postUrl = `${global.apiurl}Certificate/judgeCompliance?prodType=${global.ckFrom.privateClass}&prodId=${classId}`;
      // enableStudyCard	number
      // 是否有设置学习证书1=是；0=否
      // isReceivedStudy	number
      // 是否已经领取了证书：1=是；0=否
      // isComplianceStudy	number
      // 是否达到学习证书发放条件：1=是；0否
      // studyHonorImage	string
      // 学习证书图片（如果领取了会有图片）
      // enableBuyCard	number
      // 是否有设置入学证书1=是；0=否
      // isReceivedBuy	number
      // 是否已经领取了入学证书：1=是；0=否
      // isComplianceBuy	number
      // 是否达到入学证书发放条件：1=是；0否
      // buyHonorImage	string
      // 入学证书证书图片（如果领取了会有图片）
      utilJs.getMethod(postUrl, res => {
        if (res.enableBuyCard == 1 && res.isComplianceBuy == 1 && res.isReceivedBuy == 0) {
          this.isReceivedBuy = res.isReceivedBuy
          let enrolCerLoca = global.ckFrom.privateClass + '-' + classId
          if (JSON.parse(localStorage.getItem("enrolCer")) == enrolCerLoca) {
              return
          } else {
            this.$refs.enrolcerCom.drawNow('', classId, global.ckFrom.privateClass)
          }
        }
      });
    },
    getProdRelateCollocation() {
      utilJs.getMethod(`${global.apiurl}prodsCollocation/getProdRelateCollocation?prodType=115&prodId=${classId}`,
        res => {
          this.relateCollocation = res.data ? res.data.slice(0, 3) : [];
        }
      );
    },
    closeModal() {
      this.showCoupon = false;
    },
    //获取可以领取的优惠券
    getCouponList: function () {
      if (!this.couponLoading) {
        this.couponLoading = true;
        let $this = this;
        utilJs.getMethod(global.apiurl + 'redeemCodes/getCouponsByRedeemType?courseId=' + this.liveInfo.classId + '&redeemType=122&limit=10&page=' + this.couponPage, function (res) {
          $this.couponLoading = false;
          $this.couponList = $this.couponList.concat(res.data);
          $this.couponPage = res.next_page_url ? ($this.couponPage + 1) : $this.couponPage;
          $this.couponIsPage = res.next_page_url ? true : false;
        },
          failRes => {
            $this.couponLoading = false;
          }
        );
      }
    },
    // handleClickBuySales() {
    //   // 判断是否绑定手机号
    //   if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
    //     if (utilJs.goBindMobile()) return;
    //   }
    //   //关联表单并且未填写
    //   if (this.liveInfo.collectPage == 1 && this.liveInfo.collectPage != 3 && this.liveInfo.isNeedInfo == 1 && this.isShowFormlg && this.liveInfo.hasFormLog == false) {
    //     this.goJoinInfo(1);
    //     return;
    //   }
    //   let queryT = null;
    //   queryT = {
    //     cId: -1, //小班课id
    //     extId: this.liveInfo.classId, //小班课id
    //     ckFrom: global.ckFrom.flashSalesPrivatclass, //前端对限时购定义得值
    //     isFromInvite: 0,
    //     isFromOrder: "TRUE",
    //     pId: this.liveInfo.sales.pId, //限时购pid
    //     goodsRoomId: this.$route.query.goodsRoomId
    //   }
    //   this.$routerGo(this, "push", {
    //     path: "/homePage/course/coursePay",
    //     query: queryT
    //   });
    // },
    // 判断是否关注公众号
    checkUserIsFollowedMp() {
      let _this = this;
      return new Promise(function (resolve, reject) {
        utilJs.getMethod(`${global.apiurl}bargains/getMpData?bargainId=${_this.liveInfo.bargain.bargainId}`,
          res => {
            resolve(res);
          },
          failRes => {
            reject(failRes)
          }
        )
      })
    },
    handleClickBargainDetail(bargainId) {
      if (this.liveInfo.bargain.status == 1) {
        this.$showCjToast({
          text: '活动未开始，暂不能砍价！',
          type: 'warn'
        });
        return;
      }
      this.checkUserIsFollowedMp().then(res => {
        if (res.threshold == 2 && res.isFollowedMp == 0) {
          this.mpQrcode = res.mpQrcode;
          this.showAccountQcode = true;
          return;
        }
        // 判断是否绑定手机号
        if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
          if (utilJs.goBindMobile()) return;
        }
        //关联表单并且未填写
        if (this.liveInfo.collectPage == 1 && this.liveInfo.isNeedInfo == 1 && this.isShowFormlg && this.liveInfo.hasFormLog == false) {
          this.goJoinInfo(0);
          return;
        }
        if (this.liveInfo.bargain.status == 2) {
          this.$routerGo(this, "push", {
            path: "/homePage/bargain/bargainDetail",
            query: {
              bargainId: bargainId
            }
          });
        }
      })
    },
    invitePoster() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      let ckFrom = global.ckFrom.privateClass;
      let type = this.liveInfo.collage ? 3 : this.liveInfo.sales ? 2 : this.liveInfo.bargain ? 5 : 4;
      let cId = this.liveInfo.collage ? this.liveInfo.collage.collageId : this.liveInfo.sales ? this.liveInfo.sales.pId : this.liveInfo.isFriendHelper ? this.liveInfo.faId : this.liveInfo.bargain ? this.liveInfo.bargain.bargainId : '';
      let proId = classId;
      this.$routerGo(this, "push", { path: '/homePage/spread/spreadPoster', query: { type: type, ckFrom: ckFrom, cId: cId, proId: proId } });
    },
    hideDialog() {
      this.showAccountQcode = false;
    },
    falshSalesTime(status) {
      if (this.liveInfo.bargain) {
        this.liveInfo.bargain.status = status;
      } else if (this.liveInfo.sales) {
        this.faStatus = status;
      }
    },
    finishFlashSales(status) {
      if (this.liveInfo.bargain) {
        this.getLiveInfo();
      } else if (this.liveInfo.sales) {
        this.faStatus = status;
      }
      if (status == -1) {
        this.liveInfo.sales = null;
      }
    },
    clickDesc(e) {
      if (e.target.tagName == 'IMG' && e.target.src) {
        wxUtilJs.previewImage({
          current: e.target.src, // 当前显示图片的http链接
          urls: [e.target.src] // 需要预览的图片http链接列表
        });
      }
    },
    //小班课审核参与参与弹出提示框
    openCheckTip() {
      this.$cjConfirm({
        title: '提示', //
        titleCenter: true, //标题是否居中
        message: "请联系课程老师参与该课程 ", //弹窗内容
        messageCenter: true, //内容是否居中
        showMasker: true, //是否显示透明背景
        showCancelButton: false, //是否显示取消按钮
      })
    },
    //邀请好友
    spreadInvite() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      if (this.liveInfo.isInvitionCard == 0) {
        this.isShowShare = true;
        return;
      }
      let extId = this.$route.query.classId;
      this.$routerGo(this, "push", {
        path: "/homePage/spread/spreadCustom",
        query: {
          ckFrom: global.ckFrom.privateClass,
          cId: 0,
          extId: extId
        }
      })
    },
    //获取详情
    getLiveInfo() {
      utilJs.getMethod(
        global.apiurl + "livePrivateClass/" + classId + '?isSkeleton=1',
        res => {
          if (res.isDelete == 1) {
            this.$routerGo(this, "replace", {
              path: "/error/emptyPage",
              query: {
                info: "很抱歉，该直播间已下架"
              }
            });
            return;
          }
          if (!res.classId) {
            this.$routerGo(this, "replace", {
              path: "/error/emptyPage",
              query: {
                info: "很抱歉，该直播间已删除"
              }
            });
            return;
          }
          this.liveInfo = res
          this.optimal = res.optimal
          this.liveInfo.classBeginAt = this.getTimeByDate(res.classBeginAt)
          if (this.liveInfo.videoIntroUrl) {
            this.initPlayer();
          }
          // 判断限时购库存
          if (this.liveInfo.sales && this.liveInfo.sales.balance <= 0 && this.liveInfo.sales.limit != 0) {
            this.liveInfo.sales = null;
          }
          var myDate = new Date()
          if (utilJs.getTimeByDate(res.applyEndAt) == 0 || utilJs.getTimeByDate(res.applyEndAt) >= myDate.getTime()) {
            this.classOver = false
          } else {
            this.classOver = true
          }
          this.liveInfo.applyEndAt = this.getTimeByDate(res.applyEndAt)
          this.getCouponList();
          if (this.liveInfo.isBuyed == 0 && this.liveInfo.payType == 2 && this.liveInfo.isFreeBuy == 0 && this.liveInfo.price * 1 > 0) {
            this.getProdRelateCollocation();
          }
          this.judgeCompliance()
          this.wechatShare();
        }
      );
    },
    getTimeByDate: function(dateStr) {
      if (dateStr != '' && dateStr != null && dateStr != undefined) {
        let time = 0;
        let timeHead = dateStr.split(" ")[0].split("-");
        let timeEnd = dateStr.split(" ")[1].split(":");
        time = timeHead[0] + '年' + parseInt(timeHead[1]) + '月' + timeHead[2] + '日 ' + timeEnd[0] + ':' + timeEnd[1];
        return time;
      } else {
        return 0;
      }
    },
    onBlacklistTipOpen: function() {
      this.$showCjToast({
        text: '您无法继续上课！请联系管理员！',
        type: "warn",
      })
    },
    //点击直播封面
    clickLiveCover() {
      if (this.liveInfo.videoIntroUrl) {
        this.playing = true;
        this._qPlayer.play();
      }
    },
    initPlayer() {
      let videoObj = {
        videoMp4: this.liveInfo.videoIntroUrl,
        videoM3U8: this.liveInfo.videoIntroM3u8 || this.liveInfo.videoIntroUrl,
        autoplay: true,
        fluid: false,
        isCssFullScreen: true,
      };
      this._qPlayer = qPlayer = getXgplayer("liveVideoIntroParent", videoObj);
      this._qPlayer.on("play", () => {
        this.playing = true;
      })
    },
    //点击立即购买
    clickBuy() {
      if (this.liveInfo.studentTipStatus == -1) {
        //被拉黑或者付费被删除以后
        this.$showCjToast({
          text: '您无法继续上课！请联系管理员！',
          type: "warn",
        })
      } else {
        if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
          if (utilJs.goBindMobile()) return;
        }
        //关联表单并且未填写
        if (this.liveInfo.collectPage == 1 && this.liveInfo.collectPage != 3 && this.liveInfo.isNeedInfo == 1 && this.isShowFormlg && this.liveInfo.hasFormLog == false) {
          this.goJoinInfo(1);
          return;
        }
        let queryT = null;
        queryT = {
          extId: this.liveInfo.classId,
          ckFrom: global.ckFrom.privateClass,
          cId: 0,
          goodsRoomId: this.$route.query.goodsRoomId || ''
        }
        let isInSales = this.liveInfo.sales && this.liveInfo.sales.sales.status == 2 && this.optimal && this.optimal.optimalPriceType == 101;
        if (this.liveInfo.sales && this.faStatus == 2 && this.liveInfo.isBuyed == 0 && this.liveInfo.payType == 2 && this.liveInfo.isFreeBuy == 0 && this.liveInfo.price * 1 > 0 && this.liveInfo.isFull == 0 && !this.classOver) {
          queryT.cId = -1
          queryT.ckFrom = isInSales ? global.ckFrom.flashSalesPrivatclass : global.ckFrom.privateClass, //前端对限时购定义得值
          queryT.isFromInvite = 0
          queryT.isFromOrder = "TRUE"
          queryT.pId = isInSales ? this.liveInfo.sales.pId : null; //限时购pid
        }
        this.$routerGo(this, "push", {
          path: "/homePage/course/coursePay",
          query: queryT
        });
      }
    },
    clickSignUp() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.getBind) {
        if (utilJs.goBindMobile()) return;
      }
      //关联表单并且未填写
      if (this.liveInfo.collectPage != 3 && this.liveInfo.isNeedInfo == 1 && this.isShowFormlg && this.liveInfo.hasFormLog == false) {
        this.goJoinInfo();
        return;
      }
      if (isClicking) {
        return;
      }
      isClicking = true;
      let $this = this;
      utilJs.postMethod(`${global.apiurl}livePrivateClass/${this.$route.query.classId}/freeJoin`, {}, function(
        res
      ) {
        isClicking = false;
        $this.$showCjToast({
          text: "报名成功",
          type: "success",
        }).then(() => {
          $this.$routerGo($this, "push", {
            path: `/homePage/privateClass/classLiveList?classId=${$this.liveInfo.classId}`,
          });
        })
      });

    },
    goClassList() {
      if (this.liveInfo.studentTipStatus == -1) {
        //被拉黑或者付费被删除以后
        this.$showCjToast({
          text: '您无法继续上课！请联系管理员！',
          type: "warn",
        });
        return;
      }
      //关联表单并且未填写
      if (this.liveInfo.collectPage != 3 && this.liveInfo.isNeedInfo == 1 && this.isShowFormlg && this.liveInfo.hasFormLog == false) {
        this.goJoinInfo(0);
        return;
      }
      this.$routerGo(this, "push", {
        path: `/homePage/privateClass/classLiveList?classId=${this.liveInfo.classId}`,
      });
    },
    goJoinInfo(isGoPay = 0) {
      let query = {
        classId: this.liveInfo.classId,
        isGoPay: isGoPay
      }
      if (this.liveInfo.sales && this.liveInfo.sales.sales.status == 2) {
        query.pId = this.liveInfo.sales.pId;
      }
      this.$routerGo(this, "push", {
        path: `/homePage/privateClass/perfectInfo/`,
        query: query
      });
    },
    //显示密码输入框
    clickEnterPwd() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.passwordBind) {
        if (utilJs.goBindMobile()) return;
      }
      //关联表单并且未填写
      if (this.liveInfo.collectPage != 3 && this.liveInfo.isNeedInfo == 1 && this.liveInfo.hasFormLog == false) {
        this.goJoinInfo();
        return;
      }
      this.noticeText = '';
      this.showPassword = true;
    },
    changePsw() {
      this.noticeText = "";
    },
    //提交密码
    submitPassword(inputPwd) {
      if (!inputPwd.trim()) {
        this.noticeText = "*密码错误";
        return;
      }
      if (isClicking) {
        return;
      }
      isClicking = true;
      let $this = this
      utilJs.postMethod(`${global.apiurl}livePrivateClass/${this.liveInfo.classId}/pwdJoin`, {payPassword: inputPwd}, res => {
        isClicking = false;
        $this.showPassword = false;
        $this.goClassList();
      }, failRes => {
        isClicking = false;
      });
    },
    wechatShare: function() {
      let title = this.liveInfo.name || window.localStorage.getItem("shareTitle");
      if (this.liveInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      if (this.liveInfo.bargain != null && ((this.liveInfo.bargain.status == 1 && this.liveInfo.bargain.isPreheat == 1) || this.liveInfo.bargain.status == 2)) {
        title = `【邀您一起砍价】${title}`;
      }
      let shareImg = this.liveInfo.sales ? this.liveInfo.sales.shareImg : this.liveInfo.cover;
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?classId=${classId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.liveInfo.intro || "点击查看详情";
      console.log(this.liveInfo.intro)
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function() {});
    },
    //手机端分享
    appShare: function() {
      let title = this.liveInfo.name || window.localStorage.getItem("shareTitle");
      if (this.liveInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      if (this.liveInfo.bargain != null && ((this.liveInfo.bargain.status == 1 && this.liveInfo.bargain.isPreheat == 1) || this.liveInfo.bargain.status == 2)) {
        title = `【邀您一起砍价】${title}`;
      }
      let shareImg = this.liveInfo.sales ? this.liveInfo.sales.shareImg : this.liveInfo.cover;
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?classId=${classId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.liveInfo.intro || "点击查看详情";
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    },
    goVipBuy(cmpId, type) {
      this.$routerGo(this, "push", {
        path: "/member/vip/vipUp",
        query: {'prodId': cmpId, 'type': type}
      });
    },
  },
  activated() {
    setDocumentTitle("直播详情"); // eslint-disable-line
    classId = this.$route.query.classId;
    this.isiOS = navigator.userAgent.indexOf("IOSLogin") > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    this.liveInfo = {
      classBeginAt: "",
      classEndAt: "",
      classStatus: 3,
      cover: "",
    };
    this.optimal = null
    this.couponPage = 1;
    this.couponIsPage = false;
    this.couponLoading = false;
    this.showCoupon = false;
    this.showAccountQcode = false;
    this.faStatus = 1;
    this.playing = false;
    this.relateCollocation = [];
    this.couponList = [];
    this.chainInfo = '';
    this.isChainProd = false;
    this.isOpenIosGzhPay = utilJs.isOpenIosGzhPay(global.ckFrom.privateClass);
    getBindPhoneSetting(global.ckFrom.privateClass).then(res => {
      this.bindPhoneSetting = res;
    });
    utilJs.getChainInfo(global.ckFrom.privateClass, classId).then(res => {
      this.chainInfo = res;
      this.isChainProd = this.chainInfo && this.chainInfo.isChainProd;
    });
    this.getLiveInfo();
  },
  deactivated() {
    this.showCoupon = false;
    if (qPlayer) {
      destoryPlayer(qPlayer);
      qPlayer = null;
    }
  }
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only  -->
<style scoped>
.line360 {
  line-height: 9rem;
}
.tinymce-text >>> a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.closeBig >>> p > img,
.closeBig >>> section > img,
.closeBig >>> div > img,
.closeBig >>> img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.aCloseBig >>> p > a > img,
.aCloseBig >>> section > a > img,
.aCloseBig >>> div > a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
</style>
